package dom;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 15-5-6
 * Time: 下午1:40
 * To change this template use File | Settings | File Templates.
 */
public class Dom {
	public static void main(String[] args) {
		String a = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
				"<CSubmitState xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://tempuri.org/\">\n" +
				"  <State>1</State>\n" +
				"  <MsgID>1505061654352063203</MsgID>\n" +
				"  <MsgState>提交成功</MsgState>\n" +
				"  <Reserve>0</Reserve>\n" +
				"</CSubmitState>";
		String ResultString = null;
		if (a.indexOf("<State>0</State>") > 0) {
			System.out.println("获取成功过");
		} else {
			System.out.println("失败");
		}
		try {
			Pattern regex = Pattern.compile("<State>([\\d]*)</State>");
			Matcher regexMatcher = regex.matcher(a);
			if (regexMatcher.find()) {
				ResultString = regexMatcher.group();
			}
		} catch (PatternSyntaxException ex) {
			// Syntax error in the regular expression
		}
		System.out.println(ResultString);
	}
}
